<?php
require('lib/verify.php');
require('lib/has_char.php');
require('lib/is_approved.php');

$credit_id = $_GET["id"];
$system_id = $system["system_id"];

$sql = "select *, wm_bosses.*, wm_raids.*, wm_instances.* from wm_credits left join wm_bosses on wm_bosses.boss_id = credit_boss left join wm_raids on wm_credits.credit_raid = wm_raids.raid_id left join wm_instances on wm_instances.instance_id = wm_raids.raid_instance where credit_id = '$credit_id' and credit_system_id = $system_id order by credit_date asc";
$res = $db->query($sql);


if($db->num_rows($res)<1) {
 header("Location: error-wrong-system.php");
 exit;
}


$credit = $db->fetch_assoc($res);

$_category = "warmath";
$_title = "Credit / " . $credit["boss_name"] . " / " . date("D d M Y g:i a", strtotime($credit["credit_date"]));
require('lib/head.php');

$did_loot = array();

boxTop("Warmath: $_title");

?>

<b><a href="boss.php?id=<?=$credit["boss_id"]?>"><?=$credit["boss_name"]?></a></b>, <?=date("g:i a", strtotime($credit["credit_date"]))?> in <a href="raid.php?id=<?=$credit["raid_id"]?>"><?=$credit["instance_name"]?>, <?=date("D d M Y", strtotime($credit["raid_date"]))?></a><br />
<br />
<b>Loot</b>
<?php
   if($character["character_admin"]) {
     ?>
     (<?adminfeature()?> <a href="add-loot.php?id=<?=$credit["credit_id"]?>">add loot</a>)
<?php
   }
?>
<br />
<?php
$sql = "select *, wm_characters.*, wm_item_values.* from wm_loots left join wm_characters on wm_characters.character_id = loot_character left join item_cache on wm_loots.loot_item = item_cache.item_id left join wm_item_values on wm_loots.loot_item = wm_item_values.item_id where loot_system_id = $system_id and loot_credit = $credit_id and wm_item_values.item_system_id=$system_id order by item_cache.item_name asc";
$result = $db->query($sql);

if($system["system_tier"]==4) {
$wish_text[1] = "Min";
$wish_text[2] = "Mod";
$wish_text[3] = "Max";
}
else {
$wish_text[1] = "Micro";
$wish_text[2] = "Min";
$wish_text[3] = "Mod";
$wish_text[4] = "Max";
}

if(!$db->num_rows($result)) {
?>
<i>No loot</i><br /><br />
<?php
}

while($loot = $db->fetch_assoc($result)) {
?>
<?cclass($loot["character_class"])?> <?php show_link(array("item_id" =>$loot["loot_item"]))?>
<a href="character.php?id=<?=$loot["loot_character"]?>"><?=$loot["character_name"]?></a> looted for <?=$wish_text[$loot["loot_level"]]?>
 (bid: <?=number_format($loot["loot_bid"],2)?> dkp) (<?=number_format($loot["item_value"], 2)?> paid)
<?php
   if($character["character_admin"]) {
     $did_loot[$loot["loot_character"]]=1;
?>
     (<?adminfeature()?> <a href="remove-loot.php?lid=<?=$loot["loot_id"]?>&id=<?=$loot["loot_item"]?>&cid=<?=$credit_id?>&pid=<?=$loot["loot_character"]?>">remove</a>)
<?php
}
     ?>
<br />
<br />
<?php
    }
?>
<b>Attending</b><?php
   if($character["character_admin"]) {
     ?>
<form action="add-attendee.php" method="post">
     (<?adminfeature()?> 
<input type="hidden" name="so" value="0">
<input type="hidden" name="cid" value="<?=$credit["credit_id"]?>">
<select name="id">
<?php
      $cid = $credit["credit_id"];
      $sql = "select * from wm_characters where character_id not in (select attendee_character from wm_attendees where attendee_credit=$cid) and character_system_id=$system_id and character_approved = 1 order by character_name asc";
      echo $sql;
      $result = $db->query($sql);
      while($acha = $db->fetch_assoc($result)) {
?>
<option value="<?=$acha["character_id"]?>"><?=$acha["character_name"]?></option>
<?php
      }
?>

</select>
<input type="submit" value="Add">)
</form>
<?php
   }
?><br/>
<?php
$sql = "select * , wm_characters.* from wm_attendees left join wm_characters on wm_characters.character_id = wm_attendees.attendee_character where attendee_system_id = $system_id and attendee_credit = $credit_id and attendee_satout = 0 group by character_id order by character_class asc, character_name asc";
$result = $db->query($sql);
?>
<i><?=$db->num_rows($result)?> characters</i><br/>
<?php
while($attendee = $db->fetch_assoc($result)) {
?>
<?cclass($attendee["character_class"])?> <a href="character.php?id=<?=$attendee["character_id"]?>"><?=$attendee["character_name"]?></a><?php
   if($character["character_admin"]) {
     if($did_loot[$attendee["character_id"]]!=1) {
     ?>
     (<?adminfeature()?> <a href="remove-attendee.php?id=<?=$attendee["character_id"]?>&cid=<?=$credit_id?>">remove</a>)
     <?php }
   }
?><br />
<?php
    }
?>
<br/>
<b>Sitting Out</b><?php
   if($character["character_admin"]) {
     ?>
<form action="add-attendee.php" method="post">
     (<?adminfeature()?> 
<input type="hidden" name="so" value="1">
<input type="hidden" name="cid" value="<?=$credit["credit_id"]?>">
<select name="id">
<?php
      $cid = $credit["credit_id"];
      $sql = "select * from wm_characters where character_id not in (select attendee_character from wm_attendees where attendee_credit=$cid) and character_system_id=$system_id and character_approved = 1 order by character_name asc";
      echo $sql;
      $result = $db->query($sql);
      while($acha = $db->fetch_assoc($result)) {
?>
<option value="<?=$acha["character_id"]?>"><?=$acha["character_name"]?></option>
<?php
      }
?>

</select>
<input type="submit" value="Add">)
</form>
<?php
   }
?><br/>
<?php
$sql = "select * , wm_characters.* from wm_attendees left join wm_characters on wm_characters.character_id = wm_attendees.attendee_character where attendee_system_id = $system_id and attendee_credit = $credit_id and attendee_satout = 1 group by character_id order by character_class asc, character_name asc";
$result = $db->query($sql);
?>
<i><?=$db->num_rows($result)?> characters</i><br/>
<?php
while($attendee = $db->fetch_assoc($result)) {
?>
<?cclass($attendee["character_class"])?> <a href="character.php?id=<?=$attendee["character_id"]?>"><?=$attendee["character_name"]?></a><?php
   if($character["character_admin"]) {
     ?>
     (<?adminfeature()?> <a href="remove-attendee.php?id=<?=$attendee["character_id"]?>&cid=<?=$credit_id?>">remove</a>)
     <?php }
?><br />
<?php
    }
?>
<br/>
<?php
boxBot();
?>

<?php
require('lib/foot.php');
?>

